//---------------------------------------------------------------------
//  This file is part of the Background Motion solution.
// 
//  Copyright (C) Mindscape (TM).  All rights reserved.
//  http://www.mindscape.co.nz
// 
//  THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
//  KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
//  IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//  PARTICULAR PURPOSE.
//---------------------------------------------------------------------

using Microsoft.Practices.CompositeWeb.Interfaces;

using Mindscape.BackgroundMotion.Core;
using Mindscape.BackgroundMotion.Core.Model;
using Mindscape.BackgroundMotion.Website.Controllers;

namespace Mindscape.BackgroundMotion.Website.Infrastructure
{
  /// <summary>
  /// An implementation of CompositeWeb.ModuleInitializer which is used to automatically build up a list of service which are to be injected on each request
  /// </summary>
  /// <remarks>
  /// This is used automatically by the CompositeWeb framework and is used by the ServiceLocator in Global.asax
  /// </remarks>
  public class ModuleInitializer : Microsoft.Practices.CompositeWeb.ModuleInitializer
  {
    public override void Configure(IServiceCollection services, System.Configuration.Configuration moduleConfiguration)
    {
      base.Configure(services, moduleConfiguration);

      HttpContextAdapter httpContextAdapter = new HttpContextAdapter();

      services.Add<IContextItems>(httpContextAdapter);
      services.Add<IContext>(httpContextAdapter);
      services.Add<IMailSender>(new SmtpMailSender());
      services.Add<IUnitOfWorkFactory>(new DLinqUnitOfWorkFactory(Configuration.ConnectionString));
      services.Add<IRepositoryFactory>(new DLinqRepositoryFactory());
      services.Add<IReferenceDataProvider>(new ReferenceDataProvider(httpContextAdapter));
      services.Add<IMembershipController>(new MembershipController());
      services.Add<IContributionController>(new ContributionController());
    }
  }
}